package servlet.song;


import pojo.Songs;
import service.SongsService;
import service.impl.SongsServiceImpl;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/song/getSongsPages")
public class GetSongsPages extends HttpServlet {
    private SongsService songService = new SongsServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 用于首页显示的3首歌
        Integer startIndex = Integer.valueOf(request.getParameter("startIndex"));
        Integer targetTotal = Integer.valueOf(request.getParameter("targetTotal"));
        Integer pageSize = targetTotal;  // 每页显示的条目数

        // 获取所有歌曲
        List<Songs> songList = songService.selectSongList(startIndex, targetTotal);
        request.setAttribute("albums", songList);

        // 转发到首页
        RequestDispatcher dispatcher = request.getRequestDispatcher(request.getContextPath() + "/index.jsp");
        dispatcher.forward(request, response);
    }
}
